package huayang.ws;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.socket.WebSocketSession;

import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionBindingListener;
import java.io.IOException;

/**
 * Created by buhuayang on 16/7/13.
 */
public class ChatRoomSessionData implements HttpSessionBindingListener {

    private static final Logger logger = LoggerFactory.getLogger(ChatRoomSessionData.class);

    private String httpSessionId;
    private String username;

    private WebSocketSession socketSession;

    @Override
    public void valueBound(HttpSessionBindingEvent event) {
        logger.info("登录信息:[username:{},httpSessionId:{}]", username, httpSessionId);
    }

    @Override
    public void valueUnbound(HttpSessionBindingEvent event) {
        try {
            logger.info("登出信息:[username:{},httpSessionId:{}]", username, httpSessionId);
            socketSession.close();
        } catch (IOException e) {
            logger.error(e.getMessage(), e);
        }
    }

    public String getHttpSessionId() {
        return httpSessionId;
    }

    public void setHttpSessionId(String httpSessionId) {
        this.httpSessionId = httpSessionId;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public WebSocketSession getSocketSession() {
        return socketSession;
    }

    public void setSocketSession(WebSocketSession socketSession) {
        this.socketSession = socketSession;
    }

}
